#define _CRT_SECURE_NO_WARNINGS 1

/* atoi example */
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>     /* atoi */
#include<assert.h>
#include<ctype.h>
int MyAtoi(const char* str)
{
	assert(str);
	if (*str == '\0')
	{
		return 0;
	}
	while(isspace(*str))
	{
		str++;
	}
	int flag = 1;
	if (*str == '+')
	{
		flag = 1;
	}
	else if(*str=='-')
	{
		flag = -1;
	}
	long long ret = 0;
	while (*str != '\0')
	{
		if (isdigit(*str))
		{
			ret=ret*10+(*str - '0')*flag;
		}
		else
		{
			return (int)ret;
		}
		str++;
	}
	return (int)ret;
}
int main()
{
	int ret = MyAtoi("123a1");
	printf("%d", ret);
	return 0;
}